package com.cool.mybatisplus.entity;

import java.time.LocalDateTime;
import java.util.Optional;

import org.springframework.format.annotation.DateTimeFormat;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;

import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

/**
 * @author bian
 * @date 2021-03-24
 */
@Getter
@Setter
@Builder
@ToString
@TableName("sys_menu")
public class SystemMenu {
    @TableId(value = "menu_id", type = IdType.AUTO)
    private Long menuId;

    @TableField(value = "menu_name")
    private String menuName;

    @TableField(value = "parent_id")
    private Long parentId;

    @TableField(value = "order_num")
    private Integer orderNum;

    @TableField(value = "url")
    private String url;

    @TableField(value = "target")
    private String target;

    @TableField(value = "menu_type")
    private String menuType;

    @TableField(value = "visible")
    private String visible;

    @TableField(value = "perms")
    private String perms;

    @TableField(value = "icon")
    private String icon;

    @TableField(value = "create_by")
    private String createBy;

    @TableField(value = "create_time")
    @JsonFormat(pattern = "yyyy-MM-dd")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private LocalDateTime createTime;

    @TableField(value = "update_by")
    private String updateBy;

    @TableField(value = "update_time")
    @JsonFormat(pattern = "yyyy-MM-dd")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private LocalDateTime updateTime;

    @TableField(value = "remark")
    private String remark;

    public SystemMenu setCreateBy(String createBy) {
        this.createBy = Optional.ofNullable(createBy).orElse("admin");
        return this;
    }

    public SystemMenu setUpdateBy(String updateBy) {
        this.updateBy = Optional.ofNullable(updateBy).orElse("admin");
        return this;
    }

    public void createBySet(String createBy) {
        this.createBy = Optional.ofNullable(createBy).orElse("admin");
    }

    public void updateBySet(String updateBy) {
        this.updateBy = Optional.ofNullable(updateBy).orElse("admin");
    }
}
